package com.hhkj.api.withdrawal.controller;

import com.hhkj.api.sale.common.session.model.LoginSale;
import com.hhkj.api.withdrawal.model.req.ApiWithdrawalAccountReq;
import com.hhkj.api.withdrawal.service.biz.ApiSaleWithdrawalAccountBizService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.login.api.ApiLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ApiSaleWithdrawalAccountController
 *
 * @author zheng
 * @since 2023/11/5 16:34
 */
@RestController
@RequestMapping("/api/sale/withdrawal/account")
public class ApiSaleWithdrawalAccountController extends BaseController {

    @Autowired
    private ApiSaleWithdrawalAccountBizService accountBizService;

    /** 列表 */
    @ApiLogin(LoginSale.class)
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ApiWithdrawalAccountReq req) {
        return getDataTable(accountBizService.list(req));
    }

    /** 新增 */
    @ApiLogin(LoginSale.class)
    @PostMapping("")
    public AjaxResult save(@Validated @RequestBody ApiWithdrawalAccountReq req) {
        return accountBizService.save(req) ? AjaxResult.success() : AjaxResult.error();
    }

    /** 新增 */
    @ApiLogin(LoginSale.class)
    @PutMapping("")
    public AjaxResult update(@Validated @RequestBody ApiWithdrawalAccountReq req) {
        return accountBizService.update(req) ? AjaxResult.success() : AjaxResult.error();
    }

    @ApiLogin(LoginSale.class)
    @DeleteMapping("/{idList}")
    public AjaxResult removeByIdList(@PathVariable List<Long> idList) {
        return accountBizService.removeByIdList(idList) ? AjaxResult.success() : AjaxResult.error();
    }

    @ApiLogin(LoginSale.class)
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        return AjaxResult.success(accountBizService.getById(id));
    }
}
